<?php

namespace app\index\controller;

use app\common\model\Address;

use think\Controller;
use think\Request;
use app\common\model\Order as OrderModel;

class Order extends Common
{
    public function index()
    {
        #登录验证
        (new Auth())->check();
        (new Auth())->isCartSession();
        $id = session('id');
        $data= session('cart') ?  : [];
//        dump($data);

        #获取收货人信息

        $addressData = db('address')->where('id',$id)->find();
        $addressData['address'] = explode(',',$addressData['address']);
//        dump($addressData);
        return $this->template('order',compact('data','addressData'));
    }

    /**
     * 异步提交收货人信息
     * @param Address $address
     * @return int
     *
     */
    public function addresajax(Address $address)
    {
        if (request()->isAjax())
        {
            $post = $_POST;
            $res = $address->add($post);
            return $res;
        }
    }
    public function orderajax(OrderModel $order)
    {
        if (request()->isAjax())
        {
            $post = $_POST;
            $res = $order->add($post);
            return $res;

        }
    }
}
